//
//  CepService.m
//  YouthOlympic2014
//
//  Created by Li Yuhang on 14-7-1.
//  Copyright (c) 2014年 mitian. All rights reserved.
//

#import "CepService.h"

@implementation CepService


-(void) getAllCeps:(CompletionBlock)completion
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSError* error = nil;
        NSArray* result = nil;
        id jsonObj =  [self.api SelectAllCepActive:@"000000" withLan:[AppUtils getLan]];
        NSString* errorMsg = [[jsonObj objectForKey:@"ApiErrorInfo"] objectForKey:@"msg"];
        
        if (errorMsg != nil) {
            error = [NSError errorWithDomain:errorMsg code:400 userInfo:nil];
        }else{
            result =[Cep instanceList:jsonObj];
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            completion(result,error);
        });
    });
}

-(void) getCep:(NSString*) cepId
    completion:(CompletionBlock)completion
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSError* error = nil;
        Cep* result = nil;
        id jsonObj =  [self.api SelectTheOneCepActive:cepId andUserId:@"000000" withLan:[AppUtils getLan]];
        NSString* errorMsg = [[jsonObj objectForKey:@"ApiErrorInfo"] objectForKey:@"msg"];
        
        if (errorMsg != nil) {
            error = [NSError errorWithDomain:errorMsg code:400 userInfo:nil];
        }else{
            result =[Cep instance:jsonObj];
        }
        
        dispatch_async(dispatch_get_main_queue(), ^{
            completion(result,error);
        });
    });
    
}

-(NSInteger) addCepEventToSchedule:(CepEvent *)cepevent
{
    
    return 0;
}

@end
